package view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.example.administrator.text.R;

import java.util.List;
import adapter.Gridadapter;
import entity.HomeZhuYe;
import util.BitmapUtil;
import util.JumpActivityUtils;
import util.LogUtil;

/**
 * Created by liuxiaobin on 2016/9/21.
 * 首页底部15个图标加个图片的视图
 */
public class HomeBottonLLayout extends LinearLayout{
    private Context mContext;
    private float mTouchY;
    private GrapeGridview mGrapeGridview;
    private Gridadapter mGridadapter;
    private ImageView mImageView,mImageView1;
    public HomeBottonLLayout(Context context) {
        super(context);
        this.mContext = context;
        init();
    }

    private void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.view_home_button, this, true);
        mGrapeGridview = (GrapeGridview)this.findViewById(R.id.gridView_home_button);
        mImageView = (ImageView)this.findViewById(R.id.image_viewhomebutton);
        mImageView1 = (ImageView)this.findViewById(R.id.image_viewhomebutton1);
    }

    /**
     * 给视图添加数据
     * ,final String url,String pic,final String text
     */
    public void setViewData(List<HomeZhuYe.HotSiteModelsBean> listButton,final List<HomeZhuYe.AdModelsBean> adModelsBeen){

        LogUtil.eE("size",listButton.size()+"");
        mGridadapter = new Gridadapter(mContext,listButton,null,1);
        mGrapeGridview.setAdapter(mGridadapter);

        if(listButton.size() == 0 || adModelsBeen.size() != 0){
            mImageView.setVisibility(View.GONE);
            BitmapUtil.newBitmap().showBitmap(mContext,adModelsBeen.get(0).getPic(),mImageView1,R.mipmap.homepage_icon,null);
            mImageView1.setOnClickListener(new OnClickListener() {
                @Override public void onClick(View v) {
                    JumpActivityUtils.getInstance().jumpWebshipoView(mContext,adModelsBeen.get(0).getUrl(),adModelsBeen.get(0).getText());
                }
            });
        }else if(adModelsBeen.size() != 0){
            mImageView1.setVisibility(View.GONE);
            BitmapUtil.newBitmap().showBitmap(mContext,adModelsBeen.get(0).getPic(),mImageView,R.mipmap.homepage_icon,null);
            mImageView.setOnClickListener(new OnClickListener() {
                @Override public void onClick(View v) {
                    JumpActivityUtils.getInstance().jumpWebshipoView(mContext,adModelsBeen.get(0).getUrl(),adModelsBeen.get(0).getText());
                }
            });
        }

    }


}
